/**
  ******************************************************************************
  * @file    USB_Device/CustomHID_Standalone/Src/usbd_customhid_if.c
  * @author  MCD Application Team
  * @version V1.4.4
  * @date    06-May-2016
  * @brief   USB Device Custom HID interface file.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright ?2016 STMicroelectronics International N.V. 
  * All rights reserved.</center></h2>
  *
  * Redistribution and use in source and binary forms, with or without 
  * modification, are permitted, provided that the following conditions are met:
  *
  * 1. Redistribution of source code must retain the above copyright notice, 
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
  * 3. Neither the name of STMicroelectronics nor the names of other 
  *    contributors to this software may be used to endorse or promote products 
  *    derived from this software without specific written permission.
  * 4. This software, including modifications and/or derivative works of this 
  *    software, must execute solely and exclusively on microcontroller or
  *    microprocessor devices manufactured by or for STMicroelectronics.
  * 5. Redistribution and use of this software other than as permitted under 
  *    this license is void and will automatically terminate your rights under 
  *    this license. 
  *
  * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 
  * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
  * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 
  * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "./usbd_hid_custom_if.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
static int8_t USBD_HIDCustom_If_Init(void);
static int8_t USBD_HIDCustom_If_DeInit(void);
static int8_t USBD_HIDCustom_If_OutEvent(uint8_t event_idx, uint8_t *data);

/* Private variables ---------------------------------------------------------*/

extern USBD_HandleTypeDef USBD_HIDCustom_Device;




__ALIGN_BEGIN static uint8_t USBD_HIDCustom_ReportDesc[USBD_HID_CUSTOM_REPORT_DESC_SIZE] __ALIGN_END =
{
	0x06, 0x00, 0xFF,		/* USAGE_PAGE (Vendor Page: 0xFF00) */                       
	0x09, 0x01,				/* USAGE (Demo Kit)               */    
	0xa1, 0x01,				/* COLLECTION (Application)       */            
	/* 7 */

	/* REPORT_ID_01 */        
	0x85, REPORT_ID_01,		/*     REPORT_ID (1)		      */
	0x95, REPORT_ID_01_CNT, /*     REPORT_COUNT (3C)          */
	0x75, 0x08,            	/*     REPORT_SIZE (8)            */
	0x26, 0xFF, 0x00,		/*     LOGICAL_MAXIMUM (255)      */
	0x15, 0x00,				/*     LOGICAL_MINIMUM (0)        */ 
	0x09, 0x01,				/*     USAGE (ID 1) 	          */
	0x81, 0x02,				/*     INPUT (Data,Var,Abs,Vol)   */   
	/* 22 */
	
	/* REPORT_ID_02 */  
	0x85, REPORT_ID_02,		/*     REPORT_ID (2)              */
	0x95, REPORT_ID_02_CNT, /*     REPORT_COUNT (3C)          */
	0x75, 0x08,            	/*     REPORT_SIZE (8)            */
	0x26, 0xFF, 0x00,		/*     LOGICAL_MAXIMUM (255)      */
	0x15, 0x00,				/*     LOGICAL_MINIMUM (0)        */ 
	0x09, 0x01,            	/*     USAGE (ID 2)               */
	0x91, 0x02,            	/*     OUTPUT (Data,Var,Abs,Vol)  */
	/* 37 */
	
	/* REPORT_ID_03 */  
	0x85, REPORT_ID_03,		/*     REPORT_ID (3)              */
	0x95, REPORT_ID_03_CNT, /*     REPORT_COUNT (3C)          */
	0x75, 0x08,            	/*     REPORT_SIZE (8)            */
	0x26, 0xFF, 0x00,		/*     LOGICAL_MAXIMUM (255)      */
	0x15, 0x00,				/*     LOGICAL_MINIMUM (0)        */ 
	0x09, 0x01,            	/*     USAGE (ID 3)               */
	0x81, 0x02,				/*     INPUT (Cnst,Var,Abs,Vol)   */
	/* 52 */
	
	/* REPORT_ID_04 */  
	0x85, REPORT_ID_04,		/*     REPORT_ID (4)              */
	0x95, REPORT_ID_03_CNT, /*     REPORT_COUNT (3C)          */
	0x75, 0x08,            	/*     REPORT_SIZE (8)            */
	0x26, 0xFF, 0x00,		/*     LOGICAL_MAXIMUM (255)      */
	0x15, 0x00,				/*     LOGICAL_MINIMUM (0)        */ 
	0x09, 0x01,            	/*     USAGE (ID 3)               */
	0x91, 0x02,            	/*     OUTPUT (Data,Var,Abs,Vol)  */
	/* 67 */
	
	0xc0					/*     END_COLLECTION	          */

}; 

USBD_HID_CUSTOM_ItfTypeDef USBD_HID_Custom_fops = 
{
	USBD_HIDCustom_ReportDesc,
	USBD_HIDCustom_If_Init,
	USBD_HIDCustom_If_DeInit,
	USBD_HIDCustom_If_OutEvent,
};

/* Private functions ---------------------------------------------------------*/

/**
  * @brief  CustomHID_Init
  *         Initializes the CUSTOM HID media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t USBD_HIDCustom_If_Init(void)
{
	return (0);
}

/**
  * @brief  CustomHID_DeInit
  *         DeInitializes the CUSTOM HID media low layer
  * @param  None
  * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t USBD_HIDCustom_If_DeInit(void)
{
	/*
	Add your deinitialization code here 
	*/  
	return (0);
}

//#include "ringbuffer.h"


// u8 usbd_hid_rx_buff[70];
void (*usbd_hid_rx02_handle)(uint8_t *data, const uint8_t len) = NULL;
void (*usbd_hid_rx04_handle)(uint8_t *data, const uint8_t len) = NULL;

//HID Custom out事件
//id:符盘ID
//*data:数据
static int8_t USBD_HIDCustom_If_OutEvent (uint8_t id, uint8_t *data)
{ 
	switch(id)
	{
	case REPORT_ID_02: /* REPORT_ID_02 */
		// usbd_hid_rx_flag=2;
		// memcpy(usbd_hid_rx_buff,data,REPORT_ID_02_CNT);
		// ringbuffer_put(&ringbuff_hid_rx,data,REPORT_ID_02_CNT);
		// custom_rx_data_handler(data);	//数据接收处理
		if (usbd_hid_rx02_handle != NULL)
		{
			usbd_hid_rx02_handle(data, REPORT_ID_02_CNT);
		}
		break;

	case REPORT_ID_04: /* REPORT_ID_04 */
		//usbd_hid_rx_flag=4;
		//memcpy(usbd_hid_rx_buff,data,60);
		//ringbuffer_put(&ring_hid_rx_dev,data,strlen((const char*)data));
		//ringbuffer_put(&ringbuff_hid_rx,data,REPORT_ID_04_CNT);
		//custom_rx_cmd_handler(data);		//指令接收处理
		if (usbd_hid_rx04_handle != NULL)
		{
			usbd_hid_rx04_handle(data, REPORT_ID_04_CNT);
		}
		break;

	default:

		break;
	}
	return (0);
}








/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
